﻿using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using FikriKibar.Entities.Concrete;

namespace FikriKibar.DataAccess.Mapping
{
    public class FileMapping : EntityTypeConfiguration<File>
    {
        public FileMapping()
            : this("dbo")
        {
        }

        public FileMapping(string schema)
        {
            ToTable(schema + ".File");
            HasKey(x => x.Id);

            Property(x => x.Id).HasColumnName("Id").IsRequired().HasColumnType("int").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(x => x.FileGuid).HasColumnName("FileGuid").IsRequired().HasColumnType("uniqueidentifier");
            Property(x => x.FileName).HasColumnName("FileName").IsRequired().HasColumnType("nvarchar").HasMaxLength(255);
            Property(x => x.FileLength).HasColumnName("FileLength").IsRequired().HasColumnType("int");
            Property(x => x.FileType).HasColumnName("FileType").IsRequired().HasColumnType("nvarchar").HasMaxLength(255);
            Property(x => x.FileBuffer).HasColumnName("FileBuffer").IsOptional().HasColumnType("varbinary");
            Property(x => x.FilePath).HasColumnName("FilePath").IsOptional().HasColumnType("nvarchar").HasMaxLength(255);
            Property(x => x.CreateDate).HasColumnName("CreateDate").IsRequired().HasColumnType("datetime");
            Property(x => x.CreatedBy).HasColumnName("CreatedBy").IsRequired().HasColumnType("int");
            Property(x => x.UpdateDate).HasColumnName("UpdateDate").IsRequired().HasColumnType("datetime");
            Property(x => x.UpdatedBy).HasColumnName("UpdatedBy").IsRequired().HasColumnType("int");
            Property(x => x.IsApproved).HasColumnName("IsApproved").IsRequired().HasColumnType("bit");

            HasRequired(a => a.User_CreatedBy).WithMany(b => b.Files_CreatedBy).HasForeignKey(c => c.CreatedBy);
            HasRequired(a => a.User_UpdatedBy).WithMany(b => b.Files_UpdatedBy).HasForeignKey(c => c.UpdatedBy);
        }
    }

}
